Attribute VB_Name = "modArray"
'Project Name:  Array
'Host Name:     Array.modArray
'Date:
'Version:
'Revised by:    Joseph Weir

' Array, code module for FXI TD Batch.

' 2004-08-25, JFW, Initial version.

Option Explicit

Public g_formArrayBatch As formArrayBatch
Public g_formCotyBatch As formCotyBatch
Public g_formEntryBox As frmEntryBox
Public m_objReg As FSIX.IRegistry
Public g_dtAfterShipment As Date
'

' Declare Batch variables
' Public m_blnStop As Boolean
' Public m_blnPause As Boolean
'

'
' Safely get an item from a collection
'
Public Function CollectionItem(AnyCollection As Collection, ItemName As String) As Variant

    On Error GoTo ErrorExit
    CollectionItem = AnyCollection.Item(ItemName)
    Exit Function

ErrorExit:
    CollectionItem = Null
    
End Function
'


'Data Source constant
Public Function DATA_SOURCE_NAME() As String

    If m_objReg Is Nothing Then Set m_objReg = New FSIX.IRegistry

    Select Case Windows.ComputerName
    Case "CAN-00357094"
        Select Case m_objReg.GetValue(fsiDefault, "ArrayProject", "comboOrderSource") & ""
        Case "CotyPunchlistCA"
            DATA_SOURCE_NAME = "DSN=CotyPunchlistUS;PWD=cotyusabe;DBQ=C:\\Documents and Settings\\563774\\My Documents\\FXI\\Projects\\Array\\CotyRimmelMntceProgramCA_BackEndTables.mdb"
        Case "CotyPunchlistUS"
            DATA_SOURCE_NAME = "DSN=CotyPunchlistUS;PWD=cotyusabe;DBQ=C:\\Documents and Settings\\563774\\My Documents\\FXI\\Projects\\Array\\CotyRimmelMntceProgramUS_BackEndTables.mdb"
        End Select
    Case Else
        Select Case m_objReg.GetValue(fsiDefault, "ArrayProject", "comboOrderSource") & ""
        Case "CotyPunchlistCA"
            DATA_SOURCE_NAME = "DSN=CotyPunchlistCA;PWD=cotycdabe"
        Case "CotyPunchlistUS"
            DATA_SOURCE_NAME = "DSN=CotyPunchlistUS;PWD=cotyusabe"
        End Select
    End Select
    
End Function



Public Sub LogFile(strText As String, Optional strText2 As String = "")

    On Error GoTo ErrorExit

    Static m_boolRunning As Boolean
    Static dtLastLog As Date
    Dim strOne_Line As String
    Dim objFS As FileSystemObject
    Dim objInputFile As TextStream
    Dim objOutputFile As TextStream
    Dim strOutputFilename As String

    Set objFS = New FileSystemObject
    
    If Not objFS.FolderExists(Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log") Then
        objFS.CreateFolder Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log"
    End If
    
    ' On restart, save log file
    If Not m_boolRunning Then
        m_boolRunning = True
        If objFS.FileExists(Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration.log") Then
            objFS.CopyFile _
                Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration.log", _
                Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration " & Format(Now, "yyyymmddHHnnss") & ".log", _
                True
            objFS.DeleteFile Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration.log", True
        End If
    End If
    
    ' Start new log file is idle for 5+ min.
    'If DateDiff("m", Now, dtLastLog) < -5 Then
    '    Call objFS.OpenTextFile(Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration.log", ForWriting, True)
    'End If
    dtLastLog = Now
    
    ' Log
    With objFS.OpenTextFile(Application.Windows.ApplicationDataDirectory & "\FedEx\Integration\Projects\Log" & "\" & "Integration.log", ForAppending, True)
        .WriteLine Now & " " & strText & IIf(strText2 <> "", ", " & strText2, "")
        .Close
    End With
    Set objFS = Nothing
    Exit Sub
    
ErrorExit:
    Err.Raise 12345, "PassportOffice.LogFile", Err.Source & " - " & Err.Description
    
End Sub
'


Public Function OutputFileName() As String

    If Not g_formArrayBatch Is Nothing Then
        OutputFileName = Replace(g_formArrayBatch.textFilename, ".xls", " Out.csv")
        OutputFileName = Replace(OutputFileName, ".XLS", " Out.csv")
    ElseIf Not g_formCotyBatch Is Nothing Then
        OutputFileName = Replace(g_formCotyBatch.textFilename, ".csv", " Out.csv")
        OutputFileName = Replace(OutputFileName, ".CSV", " Out.csv")
    Else
        OutputFileName = "C:\ArrayOutput.csv"
    End If
    
End Function
'

